package com.aijk.ehm.sys.mq.consumer;


import com.aijk.config.MqConfig;
import com.aijk.config.PublicConfig;
import com.aijk.ehm.sys.mq.handler.CompanyDelHandler;
import com.alibaba.rocketmq.client.exception.MQClientException;
import com.lifesea.rocketmq.utils.manager.DefaultMessageConsumerManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Created by lenovo on 2016/9/27.
 */
@Component
public class SysAdminConsumer {

    private static final Logger logger = LoggerFactory.getLogger(SysAdminConsumer.class);

    private DefaultMessageConsumerManager consumerManager;

    @Autowired
    private CompanyDelHandler companyDelHandler;


    @PostConstruct
    public void init() throws MQClientException {
        consumerManager = new DefaultMessageConsumerManager();
        consumerManager.setNamesrvAddr(PublicConfig.ROCKETMQ_NAMESRVADDR);
        consumerManager.setConsumerGroup(MqConfig.GROUP_COMPANY);
        consumerManager.register(MqConfig.TOPIC_COMPANY, MqConfig.TAG_COMPANY_EVENT_DEL, companyDelHandler);// 公司删除
        consumerManager.init();
    }

    @PreDestroy
    public void destroy() {
        consumerManager.destroy();
    }

}
